#include <bits/stdc++.h>
using namespace std;
const int N = 7;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
char s[N][N];
int n, ans;
vector<int> g[N];
bool st[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

void dfs(int x, int y, int l, int r) //
{
	st[x][y] = true;
	if (l == r) // 左括号和右括号数量相同
	{
		ans = max(ans, l + r);
		st[x][y] = false;
		return;
	}
	for (int i = 0; i < 4; i++)
	{
		int a = x + dx[i], b = y + dy[i];
		if (a >= 0 && a < n && b >= 0 && b < n && !st[a][b])
		{

			if (s[a][b] == '(' && s[x][y] == ')')
				continue;
			if (s[a][b] == '(')
				dfs(a, b, l + 1, r);
			else
				dfs(a, b, l, r + 1);
		}
	}
	st[x][y] = false;
}
int main()
{

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> s[i];

	if (s[0][0] == '(')
		dfs(0, 0, 1, 0);

	cout << ans << endl;
	return 0;
}
